package com.rimi.servlet;

import com.rimi.bean.UserBean;
import com.rimi.service.MenuService;
import com.rimi.service.impl.MenuServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/v2/index")
public class IndexServlet extends HttpServlet {

    private MenuService menuService = new MenuServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取当前登录人
        UserBean user = (UserBean)req.getSession().getAttribute("user");
        //根据登录人的角色ID 查询对应的菜单列表
        req.setAttribute("menuList",menuService.getMenuListByRoleId(user.getUserRole()));
        req.getRequestDispatcher("/WEB-INF/pages/index.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
